package org.hswebframework.example.crud.web;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import org.hswebframework.example.crud.entity.TestEntity;
import org.hswebframework.ezorm.rdb.mapping.ReactiveRepository;
import org.hswebframework.web.authorization.annotation.QueryAction;
import org.hswebframework.web.crud.web.reactive.ReactiveCrudController;
import org.hswebframework.web.exception.NotFoundException;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Mono;

@AllArgsConstructor
@RestController
@RequestMapping("/api/test")
@Tag(name = "简单测试")
public class TestController implements ReactiveCrudController<TestEntity,String> {

   private final ReactiveRepository<TestEntity, String> repository;

    @Override
    public ReactiveRepository<TestEntity, String> getRepository() {
        return repository;
    }


    @GetMapping("/getEntById")
    @QueryAction
    @Operation(summary = "根据ID查询Test")
    public Mono<TestEntity> getTeById(String id){
        return getRepository()
                .findById(id)
                .switchIfEmpty(Mono.error(NotFoundException::new));
    }







}
